﻿using Newtonsoft.Json;
using System;

namespace DotNet.Utilities
{
    public class ResMessage
    {
        public bool success { get; set; }

        public int code { get; set; }

        public string msg { get; set; }

        public object data { get; set; }

        public long count { get; set; }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static ResMessage Success(dynamic data = null, long count = 0)
        {
            return
            new ResMessage()
            {
                success = true,
                code = 200,
                msg = "success",
                count = count,
                data = data
            };
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static ResMessage Success(string message, dynamic data = null, long count = 0)
        {
            return
            new ResMessage()
            {
                success = true,
                code = 200,
                msg = message,
                count = count,
                data = JsonConvert.SerializeObject(data)
            };
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResMessage Fail(string message = "")
        {
            return new ResMessage()
            {
                success = false,
                code = 400,
                msg = message
            };
        }

        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResMessage Fail(int code, string message = "")
        {
            return new ResMessage()
            {
                success = false,
                code = code,
                msg = message
            };
        }
        /// <summary>
        /// 登陆失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResMessage LoingFail(string message)
        {
            return new ResMessage()
            {
                success = false,
                code = 300,
                msg = message
            };
        }
    }
}
